package com.manage.platform.controller;

import com.manage.platform.dto.DictValueDto;
import com.manage.platform.dto.query.DictValuePageQuery;
import com.manage.platform.service.impl.DictValueServiceImpl;
import com.manage.platform.utils.R;
import com.manage.platform.utils.RPage;
import com.manage.platform.vo.DictPartVo;
import com.manage.platform.vo.DictValueVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * YWD
 * 2025/9/25
 */
@AllArgsConstructor
@RestController
@RequestMapping("/dictValue")
@Tag(name = "系统设置-字典值管理")
public class DictValueController {
    
    private final DictValueServiceImpl dictValueServiceImpl;

    @PostMapping("/getDictValuePage")
    @Operation(summary = "查询字典(值)列表(分页)")
    public R<RPage<List<DictValueVo>>> getDictValuePage(@RequestBody DictValuePageQuery query) {
        return R.ok(dictValueServiceImpl.getDictValuePage(query));
    }

    @GetMapping("/getDictValueDetails/{id}")
    @Operation(summary = "查询字典(值)详情")
    public R<DictValueVo> getDictValueDetails(@Schema(description = "字典(值)ID") @PathVariable("id") Long id){
        return R.ok(dictValueServiceImpl.getDictValueDetails(id));
    }

    @PostMapping("/saveDictValue")
    @Operation(summary = "添加字典(值)")
    public R<Boolean> saveDictValue(@RequestBody DictValueDto dto){
        return R.ok(dictValueServiceImpl.saveDictValue(dto));
    }

    @PutMapping("/updateDictValue")
    @Operation(summary = "修改字典(值)")
    public R<Boolean> updateDictValue(@RequestBody DictValueDto dto){
        return R.ok(dictValueServiceImpl.updateDictValue(dto));
    }

    @DeleteMapping("/deleteDictValue/{id}")
    @Operation(summary = "删除字典(值)")
    public R<Boolean> deleteDictValue(@Schema(description = "字典(值)ID") @PathVariable("id") Long id){
        return R.ok(dictValueServiceImpl.deleteDictValue(id));
    }

    @GetMapping("/getDictPartList")
    @Operation(summary = "字典列表(筛选项)")
    public R<List<DictPartVo>>  getDictPartList(@RequestParam(value = "字典名称",required = false) String dictName){
       return R.ok(dictValueServiceImpl.getDictPartList(dictName));
    }

}
